package com.anysoft.web;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebView;

import com.anysoft.WebViewNetworkProtocol;
import com.anysoft.event.FundBuyResultEvent;
import com.anysoft.event.TimeOutEvent;
import com.anysoft.me.base.BaseWebViewActivity;
import com.anysoft.utils.AnalyticsEventUtils;
import com.anysoft.utils.CommonUtil;
import com.anysoft.utils.MentorLogger;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import static com.anysoft.HostConstant.HOST_WEB_URL_HEADER;

/**
 * Created by wwq on 2017/3/16.
 *  废弃掉了
 */

public class AssetsFundtransResultActivity extends BaseWebViewActivity {

    private String param;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isShowTitleBar(true);
        title.setText("转换结果");
        leftButton.setVisibility(View.GONE);
        ivLeftButton.setVisibility(View.GONE);
        title.setText(getIntent().getStringExtra("title"));
        param = getIntent().getStringExtra("param");
        loadUrl = HOST_WEB_URL_HEADER + "transResult.html?" + param + "&isFromApp=true&token=" + getToken() + "&cusNo=" + getFundCustomerNo();
        if (CommonUtil.isNetWorkConnected(mActivity)) {
            setWebViewConfig(loadUrl);
        }
    }

    @Override
    public void onshouldOverrideUrlLoadingCallBack(WebView webview, String url) {
        MentorLogger.Log(TAG, "url=" + url);
        if (url.contains("prompt.html")) {
            mIntent.setClass(mActivity, SelectWarmPromptActivity.class);
            mIntent.putExtra("url", url);
            startActivity(mIntent);
        } else if (url.contains(WebViewNetworkProtocol.GOTO_FUND_LIST)) {
            EventBus.getDefault().post(new FundBuyResultEvent(true));
            finish();
        } else {
            webview.loadUrl(url);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onBackPressed() {
        EventBus.getDefault().post(new FundBuyResultEvent(true));
        AnalyticsEventUtils.toTransferResultEvent(this);
        super.onBackPressed();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTimeOutCallBack(TimeOutEvent event) {
        if (event.isSuccess) {
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
